﻿package code.admin 
{
	import flash.display.*;
	import gemini.utils.*;
	import flash.events.*;
	import caurina.transitions.*;
	public class ModuleList extends Sprite
	{
		var container;
		public var modlist;
		public var mods;
		public var mainframe;
		var list;
		var showlist
		var head;
		public var onselect;
		public function ModuleList(mf)
		{
			mainframe=mf;
			head=new adminmod();
			head.txt.text="MODULE LIST";
			head.btn.addEventListener(MouseEvent.MOUSE_DOWN,downMe);
			addChild(head);
			init();
			
		}
		public function init()
		{
			trace("module list init");
			showlist=0;
			var ld=new LoadJSONs();
			ld.addFile(mainframe.path+"php/module_list.php",this,"modlist");
			ld.onComplete(setList);
			ld.loadFiles();
			
		}
		private function setList(e)
		{
			
			
			
			
			
		}
		private function downMe(e)
		{
			if(showlist)
			{
				hideAll();
			}
			else
			{
				showList();
			}
		}
		public function showList()
		{
			if(onselect!=null)
			{
				//onselect(this);
			}
			head.bck.gotoAndStop("on");
			
			showlist=1;
			list=new Sprite();
			list.x=head.width;
			list.y=0;
			addChild(list);
			mods=[];
			for(var n=0;n<modlist.length;n++)
			{
				mods[n]=new ModuleItem(this,modlist[n].link)
				mods[n].mynum=n;
				//mods[n].y=mods[0].height*n;
				list.addChild(mods[n]);
			}
			arrangeAll(1)
			
		}
		public function arrangeAll(e=0)
		{
			var sx=0;
			var sy=0;
			var big=0;
			for(var n=0;n<mods.length;n++)
			{
				if(!e)
				{
					Tweener.addTween
					(
						mods[n],
						 {
							 x:sx,
							 y:sy,
							 time:.5,
							 delay:.01*n,
							 transition:"easeInOutQuad"
						 }		 
					 
					 )
				}
				else
				{
					mods[n].x=sx;
					mods[n].y=sy;
				}
				
				mods[n].sx=sx;
				mods[n].sy=sy;
				
				sx+=mods[n].width+5;
				if(mods[n].height>big)
				{
					big=mods[n].height;
				}
				if(n%6==5)
				{
					sx=0;
					sy+=big+5;;
				}
			}
		}
		public function hideAll()
		{
			
			head.bck.gotoAndStop("off");
			trace("HIDE ALL");
			showlist=0;
			try
			{
			removeChild(list);
			}
			catch(e)
			{
				
			}
			mods=[];
		}

	}

}